from bs4 import BeautifulSoup
import os
import pathlib
import re


def filter_person(tag):
    whois = tag.find('div', id="whois").text.strip()
    if 'Copywriter' in whois:
        return tag
    return None


def get_salary(string):
    pattern = r'\d{1,9}'
    # result = re.findall(pattern, string)[0]
    # result = re.search(pattern, string)[0]
    result = re.search(pattern, string).group()
    print(result)


def main():
    path_f = os.path.dirname(pathlib.Path(__file__))
    file_ = open(os.path.join(path_f, 'index.html')).read()

    soup = BeautifulSoup(file_, 'lxml')

    # rows = soup.find('div', class_='row')
    # print(rows)

    # rows = soup.find_all('div', class_='row')
    # print(rows[0])

    # rows = soup.find_all('div', {'class': 'row'})
    # print(rows[0])

    # rows = soup.find('a', attrs={'data-id': 'salary'})
    # print(rows)

    # alena = soup.find('div', text='Alena').parent
    # print(alena)

    # alena = soup.find('div', text='Alena').find_parent(class_='row')
    # print(alena)

    # .find_next_sibling()
    # .find_previous_sibling()

    # copywriters = []
    # persons = soup.find_all('div', class_="row")

    # for person in persons:
    #     result = filter_person(person)
    #     if result != None:
    #         copywriters.append(result)

    # print(copywriters)

    # salaries = soup.find_all('div', {'data-set': 'salary'})
    # for salary in salaries:
    #     get_salary(salary.text.strip())

    salaries = soup.find_all('div', text=re.compile('\d{1,9}'))
    for salary in salaries:
        print(salary.text.strip())

    # ^ - начало строки
    # $ - конец строки
    # . - любой символ
    # + - неограниченное количество вхождений
    # '\d' - цифра
    # '\w' - буквы, цифры, _


if __name__ == '__main__':
    main()
